package com.demo.flink;

import com.plat.paas.kafka.Message;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaProducer;

import java.util.Properties;

/**
 * @author : pengjie
 * @PackageName : com.demo.flink
 * @Description : TODO
 * @email : 627799251@qq.com
 * @Date : 2019/1/29 16:52
 */
public class KafkaProducer {
    public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        Properties properties = new Properties();
        properties.setProperty("bootstrap.servers", "192.168.1.231:9092");
        DataStream<Message> stream = env.addSource(new SimpleStringGenerator());
        stream.addSink(new FlinkKafkaProducer<>("flink-test2", new KafkaMessageSchema(), properties));
        env.execute("KafkaProducerDemo");
    }
}
